<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
      * {
        margin-top: 10px;
      }
      .box {
        height: 100px;
        width: 100px;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <!-- 字符串方式 -->
      <div class="box" :style="`background:${isRed? 'red':'green'}`"></div>
      <!-- 对象方式 -->
      <div class="box" :style="{background:isRed?'red':'green'}"></div>
      <!-- 数组方式 -->
      <div class="box" :style="[style1,style2]"></div>
    </div>
    <script>
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            isRed: true,
            style1: {
              border: "1px solid #000",
            },
            style2: {
              color: "pink",
            },
          };
        },
      });
    </script>
  </body>
</html>
